﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using XsqTech.SmartOA.Domain.Table;
using XsqTech.SmartOA.Dtos.DTO.Dict;
using XsqTech.SmartOA.EFCore;
using XsqTech.SmartOA.IService;

namespace XsqTech.SmartOA.Application.Controllers
{
    /// <summary>
    /// 数据字典
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class DictController : ControllerBase
    {
        public IDictService _jie;
        public MyDbContext _db;
        /// <summary>
        /// 依赖注入
        /// </summary>
        /// <param name="jie"></param>
        public DictController(IDictService jie)
        {
            _jie = jie;
        }
        /// <summary>
        /// 数据字典树形显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("getdictshow")]
        public IActionResult GetDictShow()
        {
            return Ok(new { data = _jie.GetDict() });
        }
        /// <summary>
        /// 数据字典添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("pustdictadd")]
        public IActionResult PustDictAdd(Dict model)
        {
            //var cl = HttpContext.User.FindFirst("UName").Value;

            model.DictCreateUser = "abmin";
            model.DictUpdateUser = "abmin";
            _jie.PustDictAdd(model);
            return Ok(new { mag = "操作成功" });
        }
        /// <summary>
        /// 数据字典主表删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("deletedict")]
        public IActionResult DeleteDict(int id)
        {
            _jie.DeleteDict(id);
            return Ok(new { mag = "操作成功" });
        }
        /// <summary>
        /// 数据字典修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("updatedict")]
        public IActionResult UpdateDict(DictUpdateDto model)
        {
            model.DictUpdateUser = "abmin";
            _jie.UpdateDict(model);


            return Ok(new { mag = "操作成功" });

        }
        /// <summary>
        /// 数据字典反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("dictmainrefill")]
        public Dict DictMainRefill(int id)
        {
            return _jie.DictMainRefill(id);
        }
    }
}